import 'package:bluetooth_protocols_plugin/src/tools/extension_enum.dart';

/*
  0 成功
  1 输入参数错误
  2 目标设备不支持此操作
  3 当前状态不允许进行此操作
  4 无操作权限
  5 内部执行错误
*/

// 固件升级错误类型
enum FirmwareUpgradeErrorType {
  success(0),
  invalidParameter(1),
  unsupportedDevice(2),
  invalidState(3),
  noPermission(4),
  internalError(5);

  final int rawValue;
  const FirmwareUpgradeErrorType(this.rawValue);

  String get name {
    switch (this) {
      case FirmwareUpgradeErrorType.success:
        return "Success";
      case FirmwareUpgradeErrorType.invalidParameter:
        return "Invalid parameter";
      case FirmwareUpgradeErrorType.unsupportedDevice:
        return "Unsupported device";
      case FirmwareUpgradeErrorType.invalidState:
        return "Invalid state operation";
      case FirmwareUpgradeErrorType.noPermission:
        return "No permission";
      case FirmwareUpgradeErrorType.internalError:
        return "Internal execution error";
    }
  }

  // 通过 rawValue 获取枚举类型
  static FirmwareUpgradeErrorType? getTypeByNum(int rawValue) =>
      FirmwareUpgradeErrorType.values
          .firstWhereOrNull((activity) => activity.rawValue == rawValue);
}
